package Util;

import java.io.*;

public class FIleUtil {
    public  static void writeObject(String path,Object obj ){
        FileOutputStream fos = null;
        ObjectOutputStream oos = null;
        try {
            System.out.println("write");
            fos =new FileOutputStream(path);
            oos = new ObjectOutputStream(fos);
            oos.writeObject(obj);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        finally {
            if (fos !=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (oos !=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
    public static Object readObject(String path){
        System.out.println("read");
        FileInputStream fis =null;
        ObjectInputStream ois = null;
        Object obj =null;
        try {
            fis= new FileInputStream(path);
            ois= new ObjectInputStream(fis);
            return obj= ois.readObject();


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        finally {
            if (fis !=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (ois != null){
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
     return null ;

    }
}
